﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using micsun;

namespace tmsWeb.Sys
{
    public partial class SysPwd : micsun.Web.SecurityPage
    {
        private commfuncs.SYS.User usr = new commfuncs.SYS.User();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetControls();
                SetData();
            }
        }

        void SetControls()
        {
            lblTitle.Text = "用户密码修改页面";
            
            
            btn_OK.Text = "修改";
            btn_OK.CausesValidation = true;
           
        }

        private void SetData()
        {
            txtID.Text = this.User.ID;
            txtName.Text = this.User.UserName;
           
        }

        protected void btn_OK_Click(object sender, EventArgs e)
        {
            //if (!CheckData(op))
            //{ return; }
            usr.USERID = txtID.Text;
            usr.Select(usr.USERID);
            usr.USERNAME = txtName.Text;
            string t_pwd = usr.PASSWORD;
            string OldPwd = txtOldPSW.Text;

            OldPwd = CommonFunction.BytesToString(micsun.CryptoServices.ComputeHash(OldPwd));
            if (OldPwd != t_pwd)
            {
                AddMessage("旧用户密码不正确，请重新输入！");
                return;
            }
            if (txtNewPSW.Text.Length != 0)
            {
                if (txtNewPSW.Text == txtREPSW0.Text)
                {
                    usr.PASSWORD = txtNewPSW.Text;
                }
                else
                {
                    AddMessage("用户密码必须和确认密码一致！");
                    return;
                }
            }
            usr.LASTMODUSER = this.User.UserName;
            usr.LASTMODDATE = DateTime.Now;

            if (usr.Update(true))
            {
                AddMessage("用户密码修改成功！");
            }
            else
            {
                AddMessage("修改失败");
            }
        }

        protected void btn_Cancel_Click(object sender, EventArgs e)
        {
            Transfer.Redirect("SYS/SYSMain.aspx");
        }
    }
}
